/*
	Handles the setup of the app, loads AngularJs
	dependencies and handles routing
	
*/
var app = angular.module('skiApp', [
    'ngRoute',
    'ngTouch'
])
.config(function($routeProvider){
	
	$routeProvider
		// HOME PAGE
		.when('/', {
			templateUrl: 'app/components/home/homeView.html',
			controller: 'homeController',
			controllerAs: 'home'
		})
		
		// PROGRAM PAGE
		.when('/program', {
			templateUrl: 'app/components/program/programView.html',
			controller: 'programController',
			controllerAs: 'program'
		})
		// RACE-FACTS PAGE
		.when('/race-facts', {
			templateUrl: 'app/components/race-facts/race-factsView.html',
			controller: 'raceFactsController',
			controllerAs: 'results'
		})
		// EAT & DRINK PAGE
		.when('/eat-drink', {
			templateUrl: 'app/components/eat-drink/eatDrinkView.html',
			controller: 'eat-drinkController',
			controllerAs: 'eat-drink'
		})
                // AKI'S GRILL PAGE
		.when('/eat-drink/akis-grill', {
			templateUrl: 'app/components/eat-drink/akis-grill/akisGrillView.html'
		})
                // FAMILY CORNER PAGE
		.when('/eat-drink/family-corner', {
			templateUrl: 'app/components/eat-drink/family-corner/familyCornerView.html'
		})
                // KISAMAKKARA PAGE
		.when('/eat-drink/kisamakkara', {
			templateUrl: 'app/components/eat-drink/kisamakkara/kisamakkaraView.html'
		})
                // SOUP BAR PAGE
		.when('/eat-drink/soup-bar', {
			templateUrl: 'app/components/eat-drink/soup-bar/soupBarView.html'
		})
                // SUOMI STYLE PAGE
		.when('/eat-drink/suomi-style', {
			templateUrl: 'app/components/eat-drink/suomi-style/suomiStyleView.html'
		})
                // TEXMEX PAGE
		.when('/eat-drink/texmex', {
			templateUrl: 'app/components/eat-drink/texmex/texmexView.html'
		})
		// SOCIAL MEDIA PAGE
		.when('/some', {
			templateUrl: 'app/components/some/someView.html',
			controller: 'someController',
			controllerAs: 'some'
		})
		// FAVORITES PAGE
                .when('/favorites', {
                        templateUrl: 'app/components/favorites/favoritesView.html'
                })
		// INFO PAGE
		.when('/info', {
			templateUrl: 'app/components/info/infoView.html'
		})
		// TICKETS PAGE
		.when('/info/tickets', {
			templateUrl: 'app/components/info/tickets/ticketsView.html',
                        controller: 'infoController'
		})
		// GENERAL INFO PAGE
		.when('/info/general-info', {
			templateUrl: 'app/components/info/general-info/generalInfoView.html'

		})
		// MEET LAHTI PAGE
		.when('/info/meet-lahti', {
			templateUrl: 'app/components/info/meet-lahti/meetLahtiView.html'
		})
		// FOR KIDS PAGE
		.when('/info/for-kids', {
			templateUrl: 'app/components/info/for-kids/forKidsView.html'

		})
                // EVENT PAGES
                .when('/events/ski-jumping', {
                        templateUrl: 'app/components/events/ski-jumping/skiJumpingView.html',
                        controller: 'eventController'
                })
                .when('/events/team-ski-jumping', {
                        templateUrl: 'app/components/events/ski-jumping/skiJumpingTeamView.html',
                        controller: 'eventController'
                })
                .when('/events/cross-country-sprint', {
                        templateUrl: 'app/components/events/cross-country/crossCountrySprintView.html',
                        controller: 'eventController'
                })
                .when('/events/cross-country-men-15', {
                        templateUrl: 'app/components/events/cross-country/crossCountryMen15kmView.html',
                        controller: 'eventController'
                })
                .when('/events/cross-country-ladies-10', {
                        templateUrl: 'app/components/events/cross-country/crossCountryLadies10kmView.html',
                        controller: 'eventController'
                })
                .when('/events/nordic-combined-individual', {
                        templateUrl: 'app/components/events/nordic-combined/nordicCombinedIndividualView.html',
                        controller: 'eventController'
                })
                .when('/events/nordic-combined-team', {
                        templateUrl: 'app/components/events/nordic-combined/nordicCombinedTeamView.html',
                        controller: 'eventController'
                })
		
		.otherwise({
			redirectTo: '/'
		});
		
})
.controller('appController', function($scope, $location) {
    
        $scope.$on('$locationChangeStart', function(){
            $scope.menuClassVar = "";
        });

	$scope.toggleMenu = function(){
            if($scope.menuClassVar === "active"){
                $scope.menuClassVar = "";
            } else {
                $scope.menuClassVar = "active";
            }
	};
        $scope.swipeRight = function (){
            // Disable swiping out the menu in program page
            if($location.path() !== "/program"){
                $scope.menuClassVar = "active";
            }
        };
        $scope.swipeLeft = function(){
            // Disable swiping out the menu in program page
            if($location.path() !== "/program"){
                $scope.menuClassVar = "";
            }
        };
});
